//
//  SelfClaimViewController.m
//  MemberProject
//
//  Created by vincent luo on 15/7/17.
//  Copyright (c) 2015年 MAC OS X. All rights reserved.
//

#import "SelfClaimViewController.h"
#import "SelfClaimTableViewCell.h"
#import "ClaimBankInfoViewController.h"
#import "CityFileManager.h"
#import "SignInfoViewController.h"



@interface SelfClaimViewController ()
@property (nonatomic,strong) NSArray *titleArr;
@property (nonatomic,strong) NSArray *contentArr;
@property (nonatomic,strong) NSArray *picArr;

@property (nonatomic,copy) NSString *contactAddress;

@end

@implementation SelfClaimViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.mainTableView registerNib:[UINib nibWithNibName:@"SelfClaimTableViewCell" bundle:nil] forCellReuseIdentifier:@"CellIdentifier"];
    self.title = @"自助申请";
    
    [self setupView];
}

-(void)setupView
{
    self.mainTableView.tableFooterView = self.pointOutView;
    
    ModelUser *localUser =[UserInfoManager sharedManager].modelMser;
    
    self.titleArr = @[@"申请人:",@"申请类别:",@"出险日期:",@"手  机:",@"联系地址:"];
    
    NSString *applyName = localUser.userName;
    
    NSString *applyType = @"意外医疗";
    
    NSString *dangerDate = self.dangerDate;
    
    NSString *applyTel =[[BuaatVolunteerServerSDK sharedInstance]decryptStrWithPublicKey:localUser.loginMobile];
    NSString *applyPlace = [UserInfoManager sharedManager].userClaimInput.contactAddress;
    self.contactAddress = applyPlace;
    
    self.contentArr = @[applyName,applyType,dangerDate,applyTel,applyPlace];
    
    self.picArr = @[@"ios_07.png",@"ios_15.png",@"ios_23.png",@"ios_31.png",@"ios_39.png"];
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (IBAction)nextAction:(UIButton *)sender {
    
    if (self.contactAddress&&self.contactAddress.length>0) {
        
        [UserInfoManager sharedManager].userClaimInput.contactAddress =self.contactAddress;
        if (self.isChangeInfo) {
//            [[NSNotificationCenter defaultCenter]postNotificationName:ChangeClaimInfoNotification object:nil];
            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
            
        }else
        {
            ClaimBankInfoViewController *infoVC = [[ClaimBankInfoViewController alloc]initWithNibName:@"ClaimBankInfoViewController" bundle:nil];
            [self.navigationController pushViewController:infoVC animated:YES];
        }
        
        
        
    }else
    {
        [Utils showAlert:@"请填入详细的联系地址"];
    }
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier=@"CellIdentifier";
    SelfClaimTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    [cell.titleImageView setImage:[UIImage imageNamed:self.picArr[indexPath.row]]];
    cell.inputTextField.userInteractionEnabled = NO;
    cell.titleLabel.text = self.titleArr[indexPath.row];
    
    cell.contentLabel.text = self.contentArr[indexPath.row];
    
    if (indexPath.row==4) {
        [cell.actionBtn addTarget:self action:@selector(choiceDetailArea:) forControlEvents:64];
        cell.actionBtn.hidden = NO;
    }else
    {
        cell.actionBtn.hidden = YES;
    }
    
    return cell;
}

-(void)choiceDetailArea:(UIButton *)sender
{
        SelfClaimTableViewCell *cell =(SelfClaimTableViewCell *) sender.superview.superview;
    SignInfoViewController *signInfoVC = [[SignInfoViewController alloc]initWithNibName:@"SignInfoViewController" bundle:nil];
    [signInfoVC setPickViewStyle:PickViewAeraThreeChoice];
    [signInfoVC setIsDetailAddress:YES];
    [signInfoVC finishPlaceEdit:^(NSString *nameStr, NSString *codeStr) {
        cell.contentLabel.text = nameStr;
        self.contactAddress = nameStr;
    }];
    [self.navigationController pushViewController:signInfoVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
